drop table incarico; drop table legislatura; drop table partito; drop table parlamentare; drop type incaricoty; drop type parlamentarety; drop type legislaturaty; drop type REF_PartitoNT ; drop type ref_partitoty; drop type partitoty; create or replace type partitoty as object (nome varchar2(30)) / create or replace type ref_partitoty as object (partito ref partitoty) / create or replace type REF_PartitoNT as table of ref_partitoty / create or replace type legislaturaty as object (ID int, data_inizio DATE, DATA_FINE date) / create or replace type parlamentarety as object (nome varchar2(30), cognome varchar2(30), data_nascita date, salary number, partito ref partitoty, partitopassato REF_PartitoNT) / create or replace type incaricoty as object (data_inizio date, data_fine date, circoscrizione varchar(30), legislatura ref legislaturaty, parlamentare ref parlamentarety) / create table incarico of incaricoty / create table legislatura of legislaturaty / create table partito of partitoty / create table parlamentare of parlamentarety nested table partitopassato store as partitopassato_NT / insert into legislatura values (legislaturaty(1, '13-nov-2001', '13-nov-2004')); select * from legislatura; insert into partito values (partitoty('ds')); insert into partito values (partitoty('FI')); insert into parlamentare select parlamentarety('michelangelo','ceci', '13-nov-1976',200000, ref(p), null ) from partito p where p.nome='ds'; select * from parlamentare; select deref(partito).nome from parlamentare; update parlamentare set partitopassato = cast(multiset(select ref(p) from partito p where p.nome='FI')as REF_PartitoNT) where cognome='ceci'; select deref(partito).nome from parlamentare; select deref(ParNT.partito).nome from TABLE(select partitopassato from parlamentare where cognome='ceci') ParNT; insert into parlamentare select parlamentarety(DBMS_RANDOM.STRING('U',10),DBMS_RANDOM.STRING('U',10), TO_DATE( TRUNC( DBMS_RANDOM.VALUE(TO_CHAR(DATE '2000-01-01','J') ,TO_CHAR(DATE '9999-12-31','J') ) ),'J' ) ,mod(DBMS_RANDOM.random,200000), ref(p), null ) from partito p where p.nome='ds'; drop procedure populate_parlamentari; create procedure populate_parlamentari as iterations number; begin iterations:=0; loop insert into parlamentare select parlamentarety(DBMS_RANDOM.STRING('U',10),DBMS_RANDOM.STRING('U',10), TO_DATE( TRUNC( DBMS_RANDOM.VALUE(TO_CHAR(DATE '2000-01-01','J') ,TO_CHAR(DATE '9999-12-31','J') ) ),'J' ) , mod(DBMS_RANDOM.random,200000), ref(p), null ) from partito p where p.nome='ds'; iterations := iterations +1; exit when iterations=20000; end loop; end; / delete from parlamentare; exec populate_parlamentari; select * from parlamentare;